package 错误票据;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    static int N = 100010, k;
    static int[] a = new int[N];

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        for (int i = 0; i < n; i++) {
            String[] s = in.readLine().split(" ");
            for (int j = 0; j < s.length; j++) {
                a[k++] = Integer.parseInt(s[j]);
            }
        }
        Arrays.sort(a, 0, k);
        int res1 = 0, res2 = 0;
        for (int i = 1; i < k; i++) {
            if (a[i - 1] + 2 == a[i]) {
                res1 = a[i] - 1;
            }
            if (a[i - 1] == a[i]) {
                res2 = a[i];
            }
        }
        System.out.println(res1 + " " + res2);
    }
}
